package com.atguigu.tingshu.album.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author GQS @Date 2024/11/5/16:14 @Description
 *
 */
@Configuration
public class AlbumInfoFromMysqlToEsRabbitConfig {
  /**
   * 交换机
   */
  @Bean("albumInfoExchange")
  public Exchange albumInfoExchange(){
    return ExchangeBuilder.directExchange("album_info_exchange").build();
  }

  /**
   * 上架队列
   */
  @Bean("albumInfoUpperQueue")
  public Queue albumInfoUpperQueue(){
    return QueueBuilder.durable("album_info_upper_queue").build();
  }

  /**
   * 下架队列
   */
  @Bean("albumInfoDownQueue")
  public Queue albumInfoDownQueue(){
    return QueueBuilder.durable("album_info_down_queue").build();
  }

  /**
   * 上架绑定
   */
  @Bean
  public Binding albumInfoUpperQueueBinding(@Qualifier("albumInfoUpperQueue") Queue albumInfoUpperQueue,
                                            @Qualifier("albumInfoExchange") Exchange albumInfoExchange){
    return BindingBuilder.bind(albumInfoUpperQueue).to(albumInfoExchange).with("album.es.upper").noargs();
  }

  /**
   * 下架绑定
   */
  @Bean
  public Binding albumInfoDownQueueBinding(@Qualifier("albumInfoDownQueue") Queue albumInfoDownQueue,
                                            @Qualifier("albumInfoExchange") Exchange albumInfoExchange){
    return BindingBuilder.bind(albumInfoDownQueue).to(albumInfoExchange).with("album.es.down").noargs();
  }
}
